import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 引入每个组件的路由
import approvalsRouter from '@/router/modules/approvals'
import attendancesRouter from '@/router/modules/attendances'
import departmentsRouter from '@/router/modules/departments'
import employeesRouter from '@/router/modules/employees'
import permissionRouter from '@/router/modules/permission'
import salarysRouter from '@/router/modules/salarys'
import settingRouter from '@/router/modules/setting'
import socialRouter from '@/router/modules/social'
import userRouter from '@/router/modules/user'
// 动态路由
export const asyncRoutes = [
  approvalsRouter,
  departmentsRouter,
  employeesRouter,
  attendancesRouter,
  salarysRouter,
  socialRouter,
  permissionRouter,
  settingRouter
]
// 静态路由
export const constantRoutes = [

  // 附加功能页面
  userRouter,

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/test',
    component: () => import('@/views/test'),
    hidden: true
  },
  {
    path: '/import',
    component: Layout,
    hidden: true, // 隐藏在左侧菜单中
    children: [{
      path: '', // 二级路由path什么都不写 表示二级默认路由
      component: () => import('@/views/import')
    }]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    },
    // 员工查看页
    {
      path: '/detail/:id', // query传参 动态路由传参
      component: () => import('@/views/employees/detail'),
      hidden: true, // 不在左侧菜单显示
      meta: {
        title: '员工详情' // 标记当前路由规则的中文名称 后续在做左侧菜单时 使用
      }
    },
    // 打印
    {
      path: '/print/:id', // query传参 动态路由传参
      component: () => import('@/views/employees/print'),
      hidden: true, // 不在左侧菜单显示
      meta: {
        title: '打印', // 标记当前路由规则的中文名称 后续在做左侧菜单时 使用,
        icon: 'people'
      }
    }
    ]
  }

]

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }), // 管理滚动行为 如果出现滚动 切换就让 让页面回到顶部
  // routes: [...constantRoutes, ...asyncRoutes] // 临时合并所有的路由
  routes: [...constantRoutes] // 只显示静态页面
})
const router = createRouter()

export default router
